package com.example.widgetcase.slice.viewpager;

import com.example.widgetcase.ResourceTable;
import com.example.widgetcase.slice.BaseSlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.PageSlider;

import java.util.ArrayList;
import java.util.List;

public class ViewPagerTransformerAbilitySlice extends BaseSlice {

    private List<Integer> list = new ArrayList<>();

    @Override
    public int getChildUIContent() {
        return ResourceTable.Layout_ability_viewpage_transformer;
    }

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);

        list.add(ResourceTable.Media_fighting);
        list.add(ResourceTable.Media_fighting);
        list.add(ResourceTable.Media_fighting);
        list.add(ResourceTable.Media_fighting);
        list.add(ResourceTable.Media_fighting);

        initViewPager();
    }

    private void initViewPager() {
        //hos中没有找到touch事件的传递规则，直接在布局文件中扩大显示，使用padding数值
        PageSlider transformerVp = (PageSlider) findComponentById(ResourceTable.Id_transformerVp);

        transformerVp.setOrientation(Component.HORIZONTAL);
//        transformerVp.setSlidingPossible(true);
//        transformerVp.setMarginsLeftAndRight((int) PxUtil.vp2px(45), (int) PxUtil.vp2px(45));
        // 自定义转换器
        ScaleAlphaTransformer scaleAlphaTransformer = new ScaleAlphaTransformer();
        scaleAlphaTransformer.setSlider(transformerVp);
        transformerVp.addPageChangedListener(scaleAlphaTransformer);

        ViewPagerAdapter mAdapter = new ViewPagerAdapter(getContext(), list);
        transformerVp.setProvider(mAdapter);
        transformerVp.setCurrentPage(0);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

}
